package rmi;

import service.ClientService.AssessHotelService;
import service.OrderService.BrowseOrderService;
import service.OrderService.BrowseUnfilledOrderService;
import service.ManageService.ChangeHotelInfoService;
import service.OrderService.CheckOrderService;
import service.OrderService.ExceptionOrderService;
import service.OrderService.ExecutionService;
import service.OrderService.HandleExceptionOrderService;
import service.StrategyService.HotelStrategyService;
import service.ManageService.InfoService;
import service.LoginService.LoginService;
import service.ManageService.MemberShipService;
import service.ClientService.OrderHotelService;
import service.ManageService.RechargeService;
import service.ManageService.RegisterMemberService;
import service.ClientService.SearchHotelService;
import service.ManageService.UpdateHotelService;
import service.UpdateService.UpdateRoomService;
import service.ManageService.UserManagementService;
import service.StrategyService.WebsiteStrategyService;
import service.OrderService.WithdrawOrderService;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 * Created by Dell on 2016/10/25.
 */
public class RMIHelper {

   private static boolean inited = false;

    private static AssessHotelService assessHotelService;
    private static BrowseOrderService browseOrderService;
    private static BrowseUnfilledOrderService browseUnfilledOrderService;
    private static ChangeHotelInfoService changeHotelInfoService;
    private static CheckOrderService checkOrderService;
    private static ExceptionOrderService exceptionOrderService;
    private static ExecutionService executionService;
    private static HandleExceptionOrderService handleExceptionOrderService;
    private static HotelStrategyService hotelStrategyService;
    private static InfoService infoService;
    private static LoginService loginService;
    private static MemberShipService memberShipService;
    private static OrderHotelService orderHotelService;
    private static RechargeService rechargeService;
    private static RegisterMemberService registerMemberService;
    private static SearchHotelService searchHotelService;
    private static UpdateHotelService updateHotelService;
    private static UpdateRoomService updateRoomService;
    private static UserManagementService userManagementService;
    private static WebsiteStrategyService websiteStrategyService;
    private static WithdrawOrderService withdrawOrderService;



    public synchronized static void init() throws ClientInitException {
        if (inited) {
            return;
        }

        try {
            initObjects();
            inited = true;
        } catch (Exception e) {
            throw new ClientInitException(e);
        }
    }

    private static void initObjects() throws MalformedURLException, RemoteException, NotBoundException {
        String prefix = "rmi://" + RMIConfig.getServerIP() + ":" + RMIConfig.getServerPort() + "/";

        assessHotelService=(AssessHotelService)Naming.lookup(prefix+"AssessHotelService");
        browseOrderService=(BrowseOrderService)Naming.lookup(prefix+"BrowseOrderService");
        browseUnfilledOrderService=(BrowseUnfilledOrderService)Naming.lookup(prefix+"BrowseUnfilledOrderService");
        changeHotelInfoService=(ChangeHotelInfoService)Naming.lookup(prefix+"ChangeHotelInfoService");
        checkOrderService=(CheckOrderService)Naming.lookup(prefix+"CheckOrderService");
        exceptionOrderService=(ExceptionOrderService)Naming.lookup(prefix+"ExceptionOrderService");
        executionService=(ExecutionService)Naming.lookup(prefix+"ExecutionService");
        handleExceptionOrderService=(HandleExceptionOrderService)Naming.lookup(prefix+"HandleExceptionOrderService");
        hotelStrategyService=(HotelStrategyService)Naming.lookup(prefix+"HotelStrategyService");;
        infoService=(InfoService)Naming.lookup(prefix+"InfoService");
        loginService=(LoginService)Naming.lookup(prefix+"LoginService");
        memberShipService=(MemberShipService)Naming.lookup(prefix+"MemberShipService");
        orderHotelService=(OrderHotelService) Naming.lookup(prefix+"OrderHotelService");
        rechargeService=(RechargeService)Naming.lookup(prefix+"RechargeService");
        registerMemberService=(RegisterMemberService)Naming.lookup(prefix+"RegisterMemberService");
        searchHotelService=(SearchHotelService)Naming.lookup(prefix+"SearchHotelService");
        updateHotelService=(UpdateHotelService)Naming.lookup(prefix+"UpdateHotelService");
        updateRoomService=(UpdateRoomService)Naming.lookup(prefix+"UpdateRoomService");
        userManagementService=(UserManagementService)Naming.lookup(prefix+"UserManagementService");
        websiteStrategyService=(WebsiteStrategyService)Naming.lookup(prefix+"WebsiteStrategyService");
        withdrawOrderService=(WithdrawOrderService)Naming.lookup(prefix+"WithdrawOrderService");
    }

    public static AssessHotelService getAssessHotelService() {
        return assessHotelService;
    }

    public static BrowseOrderService getBrowseOrderService() {
        return browseOrderService;
    }

    public static BrowseUnfilledOrderService getBrowseUnfilledOrderService() {
        return browseUnfilledOrderService;
    }

    public static ChangeHotelInfoService getChangeHotelInfoService() {
        return changeHotelInfoService;
    }

    public static CheckOrderService getCheckOrderService() {
        return checkOrderService;
    }



    public static ExceptionOrderService getExceptionOrderService() {
        return exceptionOrderService;
    }

    public static ExecutionService getExecutionService() {
        return executionService;
    }

    public static HandleExceptionOrderService getHandleExceptionOrderService() {
        return handleExceptionOrderService;
    }

    public static HotelStrategyService getHotelStrategyService() {
        return hotelStrategyService;
    }

    public static InfoService getInfoService() {
        return infoService;
    }

    public static LoginService getLoginService() {
        return loginService;
    }


    public static MemberShipService getMemberShipService() {
        return memberShipService;
    }

    public static OrderHotelService getOrderHotelService() {
        return orderHotelService;
    }


    public static RechargeService getRechargeService() {
        return rechargeService;
    }

    public static RegisterMemberService getRegisterMemberService() {
        return registerMemberService;
    }

    public static SearchHotelService getSearchHotelService() {
        return searchHotelService;
    }


    public static UpdateHotelService getUpdateHotelService() {
        return updateHotelService;
    }

    public static UpdateRoomService getUpdateRoomService() {
        return updateRoomService;
    }


    public static UserManagementService getUserManagementService() {
        return userManagementService;
    }

    public static WebsiteStrategyService getWebsiteStrategyService() {
        return websiteStrategyService;
    }

    public static WithdrawOrderService getWithdrawOrderService() {
        return withdrawOrderService;
    }
}

